#pragma once
#include <utility> 
#include"RBTree.h"
namespace jz
{
	template<class K, class V>
	class map
	{
		struct map_keyoft
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename RBTree<K,pair<const K, V>, map_keyoft>::iterator iterator;
		typedef typename RBTree<K,pair<const K, V>, map_keyoft>::const_iterator const_iterator;
		typedef typename RBTree<K, pair<const K, V>, map_keyoft>::reverse_iterator reverse_iterator;
		typedef typename RBTree<K, pair<const K, V>, map_keyoft>::const_reverse_iterator const_reverse_iterator;

		iterator begin()
		{
			return _t.begin();
		}

		iterator end()
		{
			return _t.end();
		}

		const_iterator begin() const 
		{
			return _t.begin();
		}

		const_iterator end() const 
		{
			return _t.end();
		}


		reverse_iterator rbegin()
		{
			return  _t.rbegin();
		}

		reverse_iterator rend()
		{
			return _t.rend();
		}

		const_reverse_iterator rbegin() const 
		{
			return  _t.rbegin();
		}

		const_reverse_iterator rend() const
		{
			return _t.rend();
		}

		pair<iterator,bool> insert(pair<K, V> kv)
		{
			return _t.Inset(kv);
		}
	private:
		RBTree<K, pair<const K, V>, map_keyoft> _t;
	};
	void test_map()
	{
		map<int, int> m;
		int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
		for (auto e : a)
		{
			m.insert(make_pair(e,e));
		}

		map<int, int>::reverse_iterator it = m.rend();
		while (it != m.rbegin())
		{
			
			std::cout << it->first << ":" << it->second << std::endl;
			--it;
		}
		std::cout << std::endl;
	}
}
